import {Injectable} from '@angular/core';
import {Resolve} from '@angular/router';

import {HomeService} from '../../services/home.service';
import {SingerService} from '../../services/singer.service';
import {HomeDataType} from '../../data-types/common.types';
import {forkJoin, Observable} from 'rxjs';
import {first} from 'rxjs/operators';


@Injectable({
  providedIn: 'root',
})
export class HomeResolveService implements Resolve<HomeDataType> {
  constructor(
    private homeService: HomeService,
    private singerService: SingerService,
  ) {
  }

  resolve(): Observable<HomeDataType> {
    return forkJoin(
      [
        this.homeService.getBanners(),
        this.homeService.getHotTags(),
        this.homeService.getPersonalSheetList(),
        this.singerService.getEnterSinger()
      ]
    ).pipe(first());
  }
}
